#include <iostream>
#include <cuda_runtime.h>

__global__ void kernel(float *data) {
    int idx = threadIdx.x;
    data[idx] += 1.0f;
}
int main() {
    cudaSetDevice(1);
    // 分配主机内存
    const int N = 1024;
    float *h_in = new float[N];
    for (int i = 0; i < N; ++i) h_in[i] = 1.0f;//*(i%K);

    float *d_data;
    cudaMalloc(&d_data, N * sizeof(float));
    cudaMemcpy(d_data, h_in, N * sizeof(float), cudaMemcpyHostToDevice);
    kernel<<<1, N>>>(d_data);
    cudaDeviceSynchronize();
    
    // 释放资源
    cudaFree(d_data);
    return 0;
}